// import Vue from 'vue'
import axiosCreate from './axios-create'
import { Toast } from 'vant'
// import { useUserStore } from '@/store/modules/user'

const axios = axiosCreate({
  tokenKey: 'Authorization',
  axiosRequestConfig: {
    baseURL: localStorage.apiUrl || import.meta.env.VITE_APP_API,
    // 成功消息提示
    successMsg: false,
    // 错误消息提示
    errorMsg: true,
    // 是否需要登录
    needLogin: false,
    // loading
    showLoading: false,
    // headers
    headers: {},
    // 携带cookie
    // withCredentials: true,
    // 允许跨越
    // crossDomain:true,
  },
  showLoading(config) {
    Toast.loading({
      duration: 0, // 持续展示 toast
      forbidClick: true,
      message: typeof showLoading == 'string' ? showLoading : '加载中...',
    })
  },
  closeLoading(config) {
    Toast.clear()
  },
  goLogin(data) {
    // const userStore = useUserStore()
    // userStore.reLogin()
  },
  message(type, msg) {
    if (type == 'success') {
      Toast.success(msg)
    } else {
      Toast.fail(msg)
    }
  },
  getToken() {
    return localStorage.token
  },
})

export default axios
